home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 24 / Amiga Format AFCD24 (Feb 1998, Issue 108).iso / -seriously_amiga- / shareware / programming / other / pmdev / demos / bigmenu.c < prev    next >
C/C++ Source or Header  |  1998-01-05  |  3KB  |  111 lines

  1. //
  2. // $VER: BigMenu.c 1.5 (19.10.97)
  3. //
  4. // Popup Menu library test program
  5. //
  6. // ©1996-1997 Henrik Isaksson
  7. // All Rights Reserved.
  8. //
  9. // Run and click the mouse in the window!
  10. // This little hack is intended to test the submenus.
  11. //
  12. // WARNING! When the menu runs out of stack, it will end in a crash!
  13. //
  14.  
  15. #include <intuition/intuition.h>
  16.  
  17. #include <clib/intuition_protos.h>
  18. #include <clib/exec_protos.h>
  19. #include <clib/alib_protos.h>
  20.  
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. #include <libraries/pm.h>
  26. #include <proto/pm.h>
  27.  
  28. struct IntuitionBase    *IntuitionBase;
  29. struct GfxBase        *GfxBase;
  30. struct PopupMenuBase    *PopupMenuBase;
  31.  
  32. struct Window *w;    // This window is only needed to find out when and where the menu should appear and wich screen it's on.
  33.  
  34. void main()
  35. {
  36.     BOOL r=TRUE;
  37.     struct IntuiMessage *im,imsg;
  38.     struct PopupMenu *p;
  39.     struct PopupMenu *subs[20], *prev=0L;
  40.     int i;
  41.  
  42.     PopupMenuBase=(struct PopupMenuBase *)OpenLibrary(POPUPMENU_NAME,POPUPMENU_VERSION);            // Open the library
  43.     if(PopupMenuBase) {
  44.         IntuitionBase=(struct IntuitionBase *)PopupMenuBase->pmb_IntuitionBase;    // We let popupmenu.library open the libraries we need
  45.         GfxBase=(struct GfxBase *)PopupMenuBase->pmb_GfxBase;            // They remain valid until the library is closed!
  46.  
  47.         for(i=0;i<20;i++) {
  48.             char bfr[50];
  49.  
  50.             sprintf(bfr, "SubMenu #%ld", 20-i);
  51.  
  52.             subs[i]=PM_MakeMenu(
  53.                 PMInfo(bfr), End,
  54.                 PMItem("Next Submenu"), PM_Sub, prev, End,
  55.                 PMBar, End,
  56.                 PMItem("Quit"), PM_UserData, 5, End,
  57.             End;
  58.             prev=subs[i];
  59.         }
  60.  
  61.         p=PMMenu("Big Menu"),    // Create a big menu...
  62.             PMInfo("WARNING: Before you open all"), End,
  63.             PMInfo("the submenus, make sure you"), End,
  64.             PMInfo("have enough stack!"), End,
  65.             PMInfo("Set it to at least 10k."), End,
  66.             PMBar, End,
  67.             PMItem("Submenu"), PM_Sub, subs[19], End,
  68.             PMBar,    End,
  69.             PMItem("Quit"),    PM_UserData,    5,    End,
  70.             End;
  71.  
  72.         if(p) {
  73.  
  74.             w=OpenWindowTags(NULL,    WA_IDCMP,    IDCMP_CLOSEWINDOW|IDCMP_MOUSEBUTTONS,    // Open a little window
  75.                     WA_RMBTrap,    TRUE,
  76.                     WA_DragBar,    TRUE,
  77.                     WA_Width,    150,
  78.                     WA_Height,    100,
  79.                     WA_Left,    150,
  80.                     WA_Top,        0,
  81.                     WA_Title,    "BigMenu",
  82.                     WA_CloseGadget,    TRUE,
  83.                     TAG_DONE);
  84.             if(w) {
  85.                 while(r) {
  86.                     WaitPort(w->UserPort);                        // Wait for a message
  87.                     while((im=(struct IntuiMessage *)GetMsg(w->UserPort))) {    // Get the message
  88.                         CopyMem(im,&imsg,sizeof(struct IntuiMessage));        // Copy the contents of it
  89.                         ReplyMsg((struct Message *)im);                // Reply the message
  90.  
  91.                         switch(imsg.Class) {
  92.                             case IDCMP_CLOSEWINDOW: r=FALSE; break;
  93.                             case IDCMP_MOUSEBUTTONS:            // The user has hit a mousebutton - time to open the menu!
  94.                                 r=(BOOL)((ULONG)(PM_OpenPopupMenu(w,
  95.                                         PM_Menu,        p,
  96.                                         PM_Code,        imsg.Code,    // Must always be there!
  97.                                         TAG_DONE))-5);
  98.                             break;
  99.                         }
  100.                     }
  101.                 }
  102.                 CloseWindow(w);
  103.             } else printf("Window error!\n");
  104.  
  105.             PM_FreePopupMenu(p);
  106.  
  107.         } else printf("Menu error!\n");
  108.         CloseLibrary((struct Library *)PopupMenuBase);
  109.     }
  110. }
  111.